/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

/**
 *
 * @author 10515
 */
public class AdministratorService {
     public static void addCourse(String filePath,Object[] o){
         try(FileOutputStream fos = new FileOutputStream(filePath, true);
            OutputStreamWriter osw = new OutputStreamWriter(fos);
            BufferedWriter bw = new BufferedWriter(osw)) {
            bw.write((String)o[0] +" "+ (String)o[1] + " "+(int)o[2]+" "+(int)o[3]+System.lineSeparator());
            bw.flush();
            bw.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
     }
     public static void deleteCourse(String[] courseName,String[] teacher,int[] numSelected,int[] numOfStu){
         final String filePath = "./data/Courses.txt";
        try (OutputStream os = new FileOutputStream(filePath);
             PrintWriter pw = new PrintWriter(os);) {
            for (int i = 0; i < courseName.length; i++) {
                pw.print(courseName[i] +" "+ teacher[i] + " "+numSelected[i]+" "+numOfStu[i]+System.getProperty("line.separator"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
     }
}
